package com.interceptor.interceptordemo.resume;

import com.interceptor.interceptordemo.domain.TbResume;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author sw
 * @project interceptordemo
 * @description
 * @date 2020/5/8 18:24
 */
@Controller
@RequestMapping("/resume")
public class ResumeController  {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Autowired
    private ResumeServiceImpl resumeService;

    @RequestMapping("/getUser")
    @ResponseBody
    public String  getUser(HttpServletRequest request) {
        System.out.println("用户接口");
        return "用户信息api，当前session:"+redisTemplate.opsForValue().get("userName");
    }
    @RequestMapping("/list")
    public ModelAndView list(HttpServletRequest request){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("success");
        modelAndView.addObject("port",request.getServerPort());
        modelAndView.addObject("userName",redisTemplate.opsForValue().get("userName"));
        return modelAndView;
    }
    @RequestMapping("/delete")
    public String deleteById(TbResume resume){
        resumeService.deleteById(resume.getId());
        return "redirect:/resume/list";
    }
    @RequestMapping("/add")
    public String  insertResume(TbResume resume){
        resumeService.insertResume(resume);
        return "redirect:/resume/list";
    }
    @RequestMapping("/update")
    public String  updateById(TbResume resume){
        resumeService.updateById(resume);
        return "redirect:/resume/list";
    }
}
